function readStam
inDir='C:\Users\matthew\Desktop\Projects\Batch\analysis\mc\ascii\stam\'
outDir='C:\Users\matthew\Desktop\Projects\Batch\analysis\mc\ascii\stam\'

nCh=151;
nTrXSubj=3;
nSubjs=9;
indexFirst=3;
condition=2;

step=indexFirst+nCh;
indx1=indexFirst:step:indexFirst+step*(nTrXSubj*nSubjs*condition-1);
indx2=(indexFirst+nCh-1):step:(indexFirst+nCh-1)+step*(nTrXSubj*nSubjs*condition-1);
stepName=nTrXSubj*step;
indxName=1:stepName:1+stepName*(nSubjs*condition-1);


filter='*.xls';
files=dir(fullfile(inDir,filter));


for i=1:length(files)
    
    subjMXT=readMatrices(fullfile(inDir,files(i).name),indx1,indx2,nCh);
    
    c1=subjMXT(1:nSubjs*nTrXSubj,:,:);
    c2=subjMXT(nSubjs*nTrXSubj+1:end,:,:);
    
    one=zeros(nSubjs,nTrXSubj,nCh,nCh);
    two=zeros(nSubjs,nTrXSubj,nCh,nCh);
    
    j=1:nTrXSubj:size(c1,1);
    for s=1:size(one,1)        
        one(s,1:nTrXSubj,:,:)=c1(j(s):j(s)+(nTrXSubj-1),:,:);
        two(s,1:nTrXSubj,:,:)=c2(j(s):j(s)+(nTrXSubj-1),:,:);
    end
    
    subj.one=two;%%comp is before in the excel
    subj.two=one;
    
    [r,outfile]=strtok(files(i).name,'_')
    [outfile,r]=strtok(outfile,'.')
    outfile=strcat('plistam',outfile);
    subjNames=readNames(fullfile(inDir,files(i).name),indxName);
    
    subj.oneLabels=subjNames(nSubjs+1:end);%%comp is before in the excel
    subj.twoLabels=subjNames(1:nSubjs);
    
    save(fullfile(outDir,outfile),'subj')
    
end


function [subjM]=readMatrices(fileName,indx1,indx2,nCh)

%subjC=cell(length(indx1),1)
subjM=zeros(length(indx1),nCh,nCh);
for i=1:length(indx1)
    range=strcat('A',num2str(indx1(i)));
    range=strcat(range,':');
    range=strcat(range,'EU');
    range=strcat(range,num2str(indx2(i)));
    subjM(i,:,:)=xlsread(fileName,1,range);
    
end

function subjNames=readNames(fileName,indx1)

subjNames=cell(length(indx1),1)
for i=1:length(indx1)
    range=strcat('B',num2str(indx1(i)));
    range=strcat(range,':');
    range=strcat(range,'B');
    range=strcat(range,num2str(indx1(i)));
    [n,subjNames{i}]=xlsread(fileName,1,range);
    subjNames{i}=strtok(subjNames{i},'.');
    
end
